package edu.polsl.bio.str.frontend.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * //todo class description
 * <p/>
 * Created on: Jul 31, 2011 9:28:38 PM <br/>
 * <a href="http://www.polsl.pl">www.polsl.pl</a>
 *
 * @author lukasz.olczak@polsl.pl
 */
public class BaseServiceServlet extends RemoteServiceServlet implements org.springframework.web.servlet.mvc.Controller, ServletContextAware {
  /**
   * slf4j Logger.
   */
  private static final Logger log = LoggerFactory.getLogger(BaseServiceServlet.class.getName());

  protected ServletContext servletContext;

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
      log.debug("Processing handleRequest before.");

      doPost(request, response);

      log.debug("Processing handleRequest after.");

      return null;
    } catch (Exception e) {
      log.error("Handle request error '" + e.getMessage() + "'", e);

      return null;
    }
  }

  @Override
  public ServletContext getServletContext() {
    return servletContext;
  }

  public void setServletContext(ServletContext servletContext) {
    this.servletContext = servletContext;
  }
}
